﻿using Newtonsoft.Json;
using Newtonsoft.Json.Bson;
using Newtonsoft.Json.Linq;
using System.Runtime.CompilerServices;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace builderDesignMode.Configuration.Provider
{
    public class JsonConfigurationProvider : IxConfigurationProvider
    {
        public JsonConfigurationProvider()
        {

        }

        public Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();

        public FileConfigurationSourcex jsonConfigurationSource { get; set; }

        public void AddJsonConfigurationFile()
        {
            string jsonFilePath = jsonConfigurationSource.jsonFilePath;

            using (StreamReader file = File.OpenText(jsonFilePath))
            using (JsonTextReader reader = new JsonTextReader(file))
            {
                JObject jObject = (JObject)JToken.ReadFrom(reader);
                var value = jObject["AllowedHosts"].ToString();

                /* // json字典
                 IDictionary<string, string> keyValuePairs = new Dictionary<string, string>();
                 keyValuePairs.Add("AllowedHosts", value);*/

                // 3、设值到Data
                keyValuePairs.Add("AllowedHosts", value);
            }
        }


        public string Get(string key)
        {
            return keyValuePairs[key];
        }

        public string this[string key]
        {
            get { return keyValuePairs[key]; }
        }
    }
}
